package com.thomas.generator.component.impl;

import com.thomas.generator.component.AbstractGenerator;
import com.thomas.generator.component.CommonUtil;
import com.thomas.generator.util.DbTypeEnum;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 * @author xutao
 * @Package com.thomas.generator.component
 * @Description: ${todo}
 * @date 2019/12/11 17:00
 */
public class OracleGeneratorImpl extends AbstractGenerator {

    public static String jdbcDriver = "oracle.jdbc.driver.OracleDriver";
    @Override
    public void init() throws Exception {
        CommonUtil.setGeneratorTableName();// 初始化生成的表名
    }

    @Override
    public String getDBType() {
        return DbTypeEnum.ORALCE.getValue();
    }

    @Override
    public Connection getConnection() {
        return CommonUtil.getConnection(jdbcDriver);
    }

    @Override
    public ResultSet getTableSet() throws Exception {
        Statement stmt = getConnection().createStatement();
        return stmt.executeQuery("select * from user_tab_comments" );
    }

    @Override
    public ResultSet getColumnSet(String tableName) throws Exception {
        Statement stmt = getConnection().createStatement();
        return  stmt.executeQuery("select t.TABLE_NAME,t.COLUMN_NAME ,t.DATA_TYPE as TYPE_NAME,t.DATA_LENGTH,t.NULLABLE,b.comments as REMARKS from user_tab_columns t   left join (select * from user_col_comments  where table_name='"+tableName+"')  b on t.column_name=b.column_name " + "where t.table_name='"+tableName+"'");
    }
}
